%% Style file
%\newif\@ifvsp
%\@ifvsp=true
\newdimen\@tempdima
\newdimen\@tempdimb
\newdimen\shlokaspaceskip
\shlokaspaceskip=24pt
\newdimen\shlokavskip
\shlokavskip=0pt
\newbox\@tempboxa
\newbox\@tempboxb
\newbox\@tempboxc
\newbox\@tempboxd

%\newcommand{\vsp}{\vspace{\stretch{1}}}
\newcommand{\vsp}{\medskip}
%%%%%%% Numbers and counters %%%%%%%
\newcount\num
\newcount\tempone \newcount\temptwo
\newcommand{\devanumber}[1]{%
\num=#1\devanumberrecurse}

\newcommand{\devanumberrecurse}{%
{\tempone=\num
%  \showthe\tempone\ %
\ifnum\num > 0 
	\divide \num by 10%
	\temptwo=\num \multiply\temptwo by -10%
	\devanumberrecurse%
% 	\\stage 2\ %
% 	\showthe\temptwo\ %
% 	temp1=\number\tempone\ %
% 	num=\number\num\ %
	\advance\tempone by \temptwo%
	\devadigit
\fi
}}

\newcommand{\devadigit}{%
\ifcase\tempone०\or१\or२\or३\or४\or५\or६\or७\or८\or९\fi%\number\tempone%
}

\newcommand{\dndigit}[1]{%
\ifcase#1०\or१\or२\or३\or४\or५\or६\or७\or८\or९\fi%
}
%Shloka Counter
\newcounter{shlokacount}
\newcommand{\nextShloka}{\stepcounter{shlokacount}\devanumber\c@shlokacount\relax}
\newcommand{\resetShloka}{\setcounter{shlokacount}{0}}
\resetShloka

%Kavya
\newenvironment{kaavya}{\bgroup\resetShloka}{\egroup}

\newcommand{\twolineshloka}{\@ifstar
                     \twolineshlokaStar%
                     \twolineshlokaNoStar%
}

\newcommand{\twolineshlokaNoStar}[2]{%
\vskip\shlokavskip\vsp
\setbox\@tempboxa=\hbox{#1}%
\setbox\@tempboxb=\hbox{#2}%
\ifdim\wd\@tempboxa>\wd\@tempboxb%
\@tempdima=\wd\@tempboxa%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa ।}\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}॥\relax \nextShloka॥}}\hfil}%
\else%
\@tempdima=\wd\@tempboxb%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}।}\hbox{\box\@tempboxb॥\relax \nextShloka॥}}\hfil}%
\fi}

\newcommand{\twolineshlokaStar}[2]{%
\vskip\shlokavskip\vsp
\setbox\@tempboxa=\hbox{#1}%
\setbox\@tempboxb=\hbox{#2}%
\ifdim\wd\@tempboxa>\wd\@tempboxb%
\@tempdima=\wd\@tempboxa%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa ।}\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}॥}}\hfil}%
\else%
\@tempdima=\wd\@tempboxb%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}।}\hbox{\box\@tempboxb॥}}\hfil}%
\fi}

\newcommand{\fourlineindentedshloka}{\@ifstar
                     \fourlineindentedshlokaStar%
                     \fourlineindentedshlokaNoStar%
}

\newcommand{\fourlineindentedshlokaNoStar}[4]{%
\vskip\shlokavskip\vsp
\setbox\@tempboxa=\hbox{#1}%
\setbox\@tempboxb=\hbox{#3}%
\setbox\@tempboxc=\hbox{#2}%
\setbox\@tempboxd=\hbox{#4}%
\ifdim\wd\@tempboxa>\wd\@tempboxb%
\@tempdima=\wd\@tempboxa%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc ।}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}॥\relax \nextShloka॥}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}।}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd ॥\relax \nextShloka॥}}\hfil}%
\fi%
\else%
\@tempdima=\wd\@tempboxb%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc ।}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}॥\relax \nextShloka॥}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}।}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd ॥\relax \nextShloka॥}}\hfil}%
\fi%
\fi}

\newcommand{\fourlineindentedshlokaStar}[4]{%
\vskip\shlokavskip\vsp
\setbox\@tempboxa=\hbox{#1}%
\setbox\@tempboxb=\hbox{#3}%
\setbox\@tempboxc=\hbox{#2}%
\setbox\@tempboxd=\hbox{#4}%
\ifdim\wd\@tempboxa>\wd\@tempboxb%
\@tempdima=\wd\@tempboxa%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc ।}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}॥}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}।}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd ॥}}\hfil}%
\fi%
\else%
\@tempdima=\wd\@tempboxb%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc ।}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}॥}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}।}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd ॥}}\hfil}%
\fi%
\fi}

\newcommand{\fourlineshloka}[4]{%
\vskip\shlokavskip\vsp
\setbox\@tempboxa=\hbox{#1}%
\setbox\@tempboxb=\hbox{#3}%
\setbox\@tempboxc=\hbox{#2}%
\setbox\@tempboxd=\hbox{#4}%
\ifdim\wd\@tempboxa>\wd\@tempboxb%
\@tempdima=\wd\@tempboxa%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\box\@tempboxa}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}}%
\hbox{\hbox to \@tempdima{\unhbox\@tempboxb}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd}}\hfil}%
\fi%
\else%
\@tempdima=\wd\@tempboxb%
\ifdim\wd\@tempboxc>\wd\@tempboxd%
\@tempdimb=\wd\@tempboxc%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxc}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxd}}}\hfil}%
\else%
\@tempdimb=\wd\@tempboxd%
\hbox to \linewidth{\hfil\vbox{\hbox{\hbox to \@tempdima{\unhbox\@tempboxa}}%
\hbox{\hskip\shlokaspaceskip\hbox to \@tempdimb{\unhbox\@tempboxc}}%
\hbox{\box\@tempboxb}%
\hbox{\hskip\shlokaspaceskip\box\@tempboxd}}\hfil}%
\fi%
\fi}
